package net.googlecode.kharchenko.controllers;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.portlet.bind.annotation.RenderMapping;
import net.googlecode.kharchenko.service.InfoService;
import org.slf4j.Logger;

/**
 * Handle main request to portlet.
 *
 * @author Kharchenko Yaroslav
 */
@Controller
@RequestMapping("VIEW")
public class ViewController {

    @Autowired
    private InfoService infoService;
    private Logger logger = LoggerFactory.getLogger(ViewController.class);

    public void setInfoService(InfoService infoService) {
        this.infoService = infoService;
    }

    /**
     * Handle render request of portlet view page.
     *
     * @return Viewname and  information about text that render at screen.
     */
    @RenderMapping
    protected ModelAndView handleRenderRequestInternal() {


        ModelAndView modelAndView = new ModelAndView("View");
        logger.info("Adding info to modelAndView");
        modelAndView.addObject("info", infoService.getallInfo());
        logger.info("Return view page");
        return modelAndView;
    }
}
